package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;

import View.MainFrame;

/**
 * implements action for the combo box used to select sort mode in displaying
 * @author Vincent Francolin
 * @version : 1.0 : creation
 */
public final class ComboSortAction implements ActionListener {
	MainFrame obj;
	ContactController ctrl;
	
	/**
	 * default constructor
	 * @param obj the frame of the application
	 * @param ctrl the view of the application
	 */
	public ComboSortAction(MainFrame obj, ContactController ctrl) {
		super();
		this.obj = obj;
		this.ctrl = ctrl;
	}

	@Override
	/**
	 * called whenever an action on combo box occurred
	 */
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		JComboBox cb = (JComboBox)e.getSource();
        String selected = (String)cb.getSelectedItem();
        if(selected.equals("Creation date")){
        	obj.updateEntireList(ctrl.sortByDate());
        } else if (selected.equals("Alphanumeric order")){
        	obj.updateEntireList(ctrl.sortByAlphanumeric());
        } else if (selected.equals("Group")){
        	obj.updateEntireList(ctrl.sortByGroup());
        }
        System.out.println(selected);
	}

}
